﻿using LogisticsTrackingWebApi_V3.Models;
using LogisticsTrackingWebApi_V3.Services;

namespace LogisticsTrackingWebApi_V3.ServicesImpl.Providers
{

    /// <summary>
    /// 圆通物流查询实现
    /// </summary>
    public class YTOExpressProvider : ILogisticsProvider
    {
        public string CompanyCode => "YT";
        public string CompanyName => "圆通速递";

        public async Task<LogisticsInfo> QueryTrackingAsync(string trackingNumber)
        {
            // 模拟调用圆通API查询
            await Task.Delay(150); // 模拟网络请求延迟

            // 模拟返回结果
            return new LogisticsInfo
            {
                TrackingNumber = trackingNumber,
                CompanyCode = CompanyCode,
                CompanyName = CompanyName,
                Status = "已签收",
                Traces = new List<LogisticsTrace>
            {
                new LogisticsTrace
                {
                    Time = DateTime.Now.AddDays(-2),
                    Location = "北京市",
                    Description = "快递已发出"
                },
                new LogisticsTrace
                {
                    Time = DateTime.Now.AddDays(-1),
                    Location = "南京市",
                    Description = "快递已到达"
                },
                new LogisticsTrace
                {
                    Time = DateTime.Now.AddHours(-5),
                    Location = "南京市",
                    Description = "快递已签收，签收人：前台"
                }
            }
            };
        }

        public bool MatchTrackingNumber(string trackingNumber)
        {
            // 圆通运单号规则：10位或12位数字
            return !string.IsNullOrEmpty(trackingNumber) &&
                   (trackingNumber.Length == 10 || trackingNumber.Length == 12) &&
                   long.TryParse(trackingNumber, out _);
        }
    }
}
